<template>
  <view class="container">
    <my-navbar-top></my-navbar-top>

    <view class="title">新品推荐</view>
	<view style="padding:40rpx;flex: 1;overflow-y: auto;box-sizing: border-box;display: flex;flex-direction: column;align-items: center;">
		<scroll-view
		  class="list"
		  style="height: 100%"
		  scroll-y
		  @scrolltolower="handleScrollToLower"
		>
			<view style="margin-bottom:50rpx;" v-for="item in newList" :key="item.id" @click="goDetail(item)">
				<view class="time">{{ item.release_date }}</view>
				<view class="image">
					<image :src="item.cover" mode="widthFix" style="width:100%;" />
				</view>
				<view class="title_info">
					<view class="title_info_c">
						<view class="big_title">{{ item.big_title }}</view>
						<view class="small_title">{{ item.small_title }}</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
  </view>
</template>

<script>
import api from '@/utils/api/index.js'
export default {
  name: 'New',
  data() {
    return {
      isLoad: true,
      total: 0,
      newList: [],
      page: 1,
      isEnd: false,
    }
  },
  onShow() {
	  
  },
  onLoad(options) {
	this.initData(true)
  },
  methods: {
    initData(init = false) {
      this.$util.showLoading()
      if (init) {
        this.page = 1
        this.isEnd = false
        this.newList = []
      }
      this.isLoad = true
      let o = {
        page: this.page,
      }
      try {
        this.$api.getNewList(o).then((res) => {
          if (res.code == 0) {
            let list = res.data || []
            this.isEnd = list.length === 0
            console.log('this.isEnd', this.isEnd)
    
            this.newList = this.newList.concat(list)
            this.total = res.count || 0
    
            console.log('this.newList', this.newList.length, res.count)
          }
          uni.hideLoading()
          this.isLoad = false
        })
      } catch (error) {
        uni.hideLoading()
        this.isLoad = false
      }
    },
	handleScrollToLower() {
	  console.log('到底了')
	  if (this.isEnd) return
	  this.page++
	  this.initData()
	},
	goDetail(item) {
		console.log(3333);
	  uni.navigateTo({
	    url: `/pages/new/detail/index?id=${item.id}`,
	  })
	},
	
  },
  onShareAppMessage() {
    return {
      title: this.detail.name || '新品推荐',
      path: '/pages/new/index',
      imageUrl: this.detail.cover || '/static/images/default-cover.png',
    }
  },
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
